/*
 *  Copyright © 2018-2023 Hennadii Chernyshchyk <genaloner@gmail.com>
 *
 *  This file is part of Crow Translate.
 *
 *  Crow Translate is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Crow Translate is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Crow Translate. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef DBUSSCREENGRABBER_H
#define DBUSSCREENGRABBER_H

#include "abstractscreengrabber.h"

#include <QDBusPendingReply>

class QDBusPendingCallWatcher;

class DBusScreenGrabber : public AbstractScreenGrabber
{
    Q_OBJECT
    Q_DISABLE_COPY(DBusScreenGrabber)

public slots:
    void cancel() override;

protected:
    explicit DBusScreenGrabber(QObject *parent = nullptr);

    template<class T>
    QDBusPendingReply<T> readReply()
    {
        QDBusPendingReply<T> reply = *m_callWatcher;
        m_callWatcher->deleteLater();
        m_callWatcher = nullptr;
        return reply;
    }

    static QMap<const QScreen *, QImage> splitScreenImages(const QPixmap &pixmap);

    QDBusPendingCallWatcher *m_callWatcher;
};

#endif // DBUSSCREENGRABBER_H
